home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.text.html;
-
- import java.io.IOException;
- import java.io.Writer;
- import java.util.Enumeration;
- import java.util.Stack;
- import java.util.Vector;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.DefaultListModel;
- import javax.swing.text.AbstractDocument;
- import javax.swing.text.AbstractWriter;
- import javax.swing.text.AttributeSet;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.Document;
- import javax.swing.text.Element;
- import javax.swing.text.ElementIterator;
- import javax.swing.text.MutableAttributeSet;
- import javax.swing.text.Segment;
- import javax.swing.text.SimpleAttributeSet;
- import javax.swing.text.Style;
- import javax.swing.text.StyleConstants;
- import javax.swing.text.StyleContext;
- import javax.swing.text.html.HTML.Attribute;
- import javax.swing.text.html.HTML.Tag;
-
- public class HTMLWriter extends AbstractWriter {
- private Stack blockElementStack;
- private boolean inContent;
- private boolean inPre;
- private int preEndOffset;
- private boolean inTextArea;
- private boolean newlineOutputed;
- private boolean completeDoc;
- private Vector tags;
- private Vector tagValues;
- private char[] tempChars;
- private char[] indentChars;
- private Segment segment;
- private Vector tagsToRemove;
- private boolean wroteHead;
- private Writer out;
- private int maxLineLength;
- private int currLength;
- private int indentLevel;
- private int indentSpace;
- private int offsetIndent;
- private String newline;
- private boolean isLineEmpty;
- private int startOffset;
- private int endOffset;
- private boolean indentNext;
- private boolean writeCSS;
- private MutableAttributeSet convAttr;
- private MutableAttributeSet oConvAttr;
-
- public HTMLWriter(Writer var1, HTMLDocument var2) {
- this(var1, var2, 0, ((AbstractDocument)var2).getLength());
- }
-
- public HTMLWriter(Writer var1, HTMLDocument var2, int var3, int var4) {
- super(var1, var2, var3, var4);
- this.blockElementStack = new Stack();
- this.inContent = false;
- this.inPre = false;
- this.inTextArea = false;
- this.newlineOutputed = false;
- this.tags = new Vector(10);
- this.tagValues = new Vector(10);
- this.tagsToRemove = new Vector(10);
- this.maxLineLength = 80;
- this.indentLevel = 0;
- this.indentSpace = 2;
- this.offsetIndent = 0;
- this.indentNext = false;
- this.writeCSS = false;
- this.convAttr = new SimpleAttributeSet();
- this.oConvAttr = new SimpleAttributeSet();
- this.completeDoc = var3 == 0 && var4 == ((AbstractDocument)var2).getLength();
- this.maxLineLength = 80;
- this.out = var1;
- Object var5 = ((AbstractDocument)var2).getProperty("__EndOfLine__");
- if (var5 instanceof String) {
- this.newline = (String)var5;
- } else {
- try {
- this.newline = System.getProperty("line.separator");
- } catch (SecurityException var6) {
- }
-
- if (this.newline == null) {
- this.newline = "\n";
- }
- }
-
- this.startOffset = var3;
- this.endOffset = var3 + var4;
- }
-
- protected void closeOutUnwantedEmbeddedTags(AttributeSet var1) throws IOException {
- this.tagsToRemove.removeAllElements();
- var1 = this.convertToHTML(var1, (MutableAttributeSet)null);
- int var4 = -1;
- int var5 = this.tags.size();
-
- for(int var6 = var5 - 1; var6 >= 0; --var6) {
- HTML.Tag var2 = (HTML.Tag)this.tags.elementAt(var6);
- Object var3 = this.tagValues.elementAt(var6);
- if (var1 == null || this.noMatchForTagInAttributes(var1, var2, var3)) {
- var4 = var6;
- this.tagsToRemove.addElement(var2);
- }
- }
-
- if (var4 != -1) {
- boolean var7 = var5 - var4 == this.tagsToRemove.size();
-
- for(int var8 = var5 - 1; var8 >= var4; --var8) {
- HTML.Tag var12 = (HTML.Tag)this.tags.elementAt(var8);
- if (var7 || this.tagsToRemove.contains(var12)) {
- this.tags.removeElementAt(var8);
- this.tagValues.removeElementAt(var8);
- }
-
- this.write('<');
- this.write('/');
- this.write(var12.toString());
- this.write('>');
- }
-
- var5 = this.tags.size();
-
- for(int var9 = var4; var9 < var5; ++var9) {
- HTML.Tag var13 = (HTML.Tag)this.tags.elementAt(var9);
- this.write('<');
- this.write(var13.toString());
- Object var10 = this.tagValues.elementAt(var9);
- if (var10 != null && var10 instanceof AttributeSet) {
- this.writeAttributes((AttributeSet)var10);
- }
-
- this.write('>');
- }
- }
-
- }
-
- protected void comment(Element var1) throws BadLocationException, IOException {
- AttributeSet var2 = var1.getAttributes();
- if (this.matchNameAttribute(var2, Tag.COMMENT)) {
- Object var3 = var2.getAttribute(Attribute.COMMENT);
- if (var3 instanceof String) {
- this.writeComment((String)var3);
- } else {
- this.writeComment((String)null);
- }
- }
-
- }
-
- AttributeSet convertToHTML(AttributeSet var1, MutableAttributeSet var2) {
- if (var2 == null) {
- var2 = this.convAttr;
- }
-
- var2.removeAttributes(var2);
- if (this.writeCSS) {
- convertToHTML40(var1, var2);
- } else {
- convertToHTML32(var1, var2);
- }
-
- return var2;
- }
-
- private static void convertToHTML32(AttributeSet var0, MutableAttributeSet var1) {
- if (var0 != null) {
- Enumeration var2 = var0.getAttributeNames();
- String var3 = "";
-
- while(var2.hasMoreElements()) {
- Object var4 = var2.nextElement();
- if (var4 instanceof CSS.Attribute) {
- if (var4 != javax.swing.text.html.CSS.Attribute.FONT_FAMILY && var4 != javax.swing.text.html.CSS.Attribute.FONT_SIZE && var4 != javax.swing.text.html.CSS.Attribute.COLOR) {
- if (var4 == javax.swing.text.html.CSS.Attribute.FONT_WEIGHT) {
- CSS.FontWeight var5 = (CSS.FontWeight)var0.getAttribute(javax.swing.text.html.CSS.Attribute.FONT_WEIGHT);
- if (var5 != null && var5.getValue() > 400) {
- var1.addAttribute(Tag.B, SimpleAttributeSet.EMPTY);
- }
- } else if (var4 == javax.swing.text.html.CSS.Attribute.FONT_STYLE) {
- String var6 = var0.getAttribute(var4).toString();
- if (var6.indexOf("italic") >= 0) {
- var1.addAttribute(Tag.I, SimpleAttributeSet.EMPTY);
- }
- } else if (var4 == javax.swing.text.html.CSS.Attribute.TEXT_DECORATION) {
- String var7 = var0.getAttribute(var4).toString();
- if (var7.indexOf("underline") >= 0) {
- var1.addAttribute(Tag.U, SimpleAttributeSet.EMPTY);
- }
-
- if (var7.indexOf("line-through") >= 0) {
- var1.addAttribute(Tag.STRIKE, SimpleAttributeSet.EMPTY);
- }
- } else if (var4 == javax.swing.text.html.CSS.Attribute.VERTICAL_ALIGN) {
- String var8 = var0.getAttribute(var4).toString();
- if (var8.indexOf("sup") >= 0) {
- var1.addAttribute(Tag.SUP, SimpleAttributeSet.EMPTY);
- }
-
- if (var8.indexOf("sub") >= 0) {
- var1.addAttribute(Tag.SUB, SimpleAttributeSet.EMPTY);
- }
- } else if (var4 == javax.swing.text.html.CSS.Attribute.TEXT_ALIGN) {
- var1.addAttribute(Attribute.ALIGN, var0.getAttribute(var4).toString());
- } else {
- if (var3.length() > 0) {
- var3 = var3 + "; ";
- }
-
- var3 = var3 + var4 + ": " + var0.getAttribute(var4);
- }
- } else {
- createFontAttribute((CSS.Attribute)var4, var0, var1);
- }
- } else {
- var1.addAttribute(var4, var0.getAttribute(var4));
- }
- }
-
- if (var3.length() > 0) {
- var1.addAttribute(Attribute.STYLE, var3);
- }
-
- }
- }
-
- private static void convertToHTML40(AttributeSet var0, MutableAttributeSet var1) {
- Enumeration var2 = var0.getAttributeNames();
- String var3 = "";
-
- while(var2.hasMoreElements()) {
- Object var4 = var2.nextElement();
- if (var4 instanceof CSS.Attribute) {
- var3 = var3 + " " + var4 + "=" + var0.getAttribute(var4) + ";";
- } else {
- var1.addAttribute(var4, var0.getAttribute(var4));
- }
- }
-
- if (var3.length() > 0) {
- var1.addAttribute(Attribute.STYLE, var3);
- }
-
- }
-
- private static void createFontAttribute(CSS.Attribute var0, AttributeSet var1, MutableAttributeSet var2) {
- Object var3 = (MutableAttributeSet)var2.getAttribute(Tag.FONT);
- if (var3 == null) {
- var3 = new SimpleAttributeSet();
- var2.addAttribute(Tag.FONT, var3);
- }
-
- String var4 = var1.getAttribute(var0).toString();
- if (var0 == javax.swing.text.html.CSS.Attribute.FONT_FAMILY) {
- ((MutableAttributeSet)var3).addAttribute(Attribute.FACE, var4);
- } else if (var0 == javax.swing.text.html.CSS.Attribute.FONT_SIZE) {
- ((MutableAttributeSet)var3).addAttribute(Attribute.SIZE, var4);
- } else if (var0 == javax.swing.text.html.CSS.Attribute.COLOR) {
- ((MutableAttributeSet)var3).addAttribute(Attribute.COLOR, var4);
- }
-
- }
-
- protected void decrIndent() {
- if (this.offsetIndent > 0) {
- --this.offsetIndent;
- } else {
- --this.indentLevel;
- }
-
- }
-
- protected void emptyTag(Element var1) throws BadLocationException, IOException {
- if (!this.inContent && !this.inPre) {
- this.indent();
- }
-
- AttributeSet var2 = var1.getAttributes();
- this.closeOutUnwantedEmbeddedTags(var2);
- this.writeEmbeddedTags(var2);
- if (this.matchNameAttribute(var2, Tag.CONTENT)) {
- this.inContent = true;
- this.text(var1);
- } else if (this.matchNameAttribute(var2, Tag.COMMENT)) {
- this.comment(var1);
- } else {
- boolean var3 = this.isBlockTag(var1.getAttributes());
- if (this.inContent && var3) {
- this.writeNewline();
- this.indent();
- }
-
- Object var4 = var2 != null ? var2.getAttribute(StyleConstants.NameAttribute) : null;
- Object var5 = var2 != null ? var2.getAttribute(Attribute.ENDTAG) : null;
- boolean var6 = false;
- if (var4 != null && var5 != null && var5 instanceof String && ((String)var5).equals("true")) {
- var6 = true;
- }
-
- if (this.completeDoc && this.matchNameAttribute(var2, Tag.HEAD)) {
- if (var6) {
- this.writeStyles(((HTMLDocument)((AbstractWriter)this).getDocument()).getStyleSheet());
- }
-
- this.wroteHead = true;
- }
-
- this.write('<');
- if (var6) {
- this.write('/');
- }
-
- this.write(var1.getName());
- this.writeAttributes(var2);
- this.write('>');
- if (this.matchNameAttribute(var2, Tag.TITLE) && !var6) {
- Document var7 = var1.getDocument();
- String var8 = (String)var7.getProperty("title");
- this.write(var8);
- } else if (!this.inContent || var3) {
- this.writeNewline();
- if (var3 && this.inContent) {
- this.indent();
- }
- }
- }
-
- }
-
- protected void endTag(Element var1) throws IOException {
- if (!this.synthesizedElement(var1)) {
- if (this.matchNameAttribute(var1.getAttributes(), Tag.PRE)) {
- this.inPre = false;
- }
-
- this.closeOutUnwantedEmbeddedTags(var1.getAttributes());
- if (this.inContent) {
- if (!this.newlineOutputed) {
- this.writeNewline();
- }
-
- this.newlineOutputed = false;
- this.inContent = false;
- }
-
- this.indent();
- this.write('<');
- this.write('/');
- this.write(var1.getName());
- this.write('>');
- this.writeNewline();
- }
- }
-
- protected void incrIndent() {
- if (this.offsetIndent > 0) {
- ++this.offsetIndent;
- } else if (++this.indentLevel * this.indentSpace >= this.maxLineLength) {
- ++this.offsetIndent;
- --this.indentLevel;
- }
-
- }
-
- protected void indent() throws IOException {
- int var1 = this.indentLevel * this.indentSpace;
- if (this.indentChars == null || var1 > this.indentChars.length) {
- this.indentChars = new char[var1];
-
- for(int var2 = 0; var2 < var1; ++var2) {
- this.indentChars[var2] = ' ';
- }
- }
-
- this.out.write(this.indentChars, 0, var1);
- this.currLength += var1;
- }
-
- private boolean indentNeedsIncrementing(Element var1, Element var2) {
- if (var2.getParentElement() == var1 && !this.inPre) {
- if (this.indentNext) {
- this.indentNext = false;
- return true;
- }
-
- if (this.synthesizedElement(var2)) {
- this.indentNext = true;
- } else if (!this.synthesizedElement(var1)) {
- return true;
- }
- }
-
- return false;
- }
-
- private int indexOf(char[] var1, char var2, int var3, int var4) {
- while(var3 < var4) {
- if (var1[var3] == var2) {
- return var3;
- }
-
- ++var3;
- }
-
- return -1;
- }
-
- protected boolean isBlockTag(AttributeSet var1) {
- Object var2 = var1.getAttribute(StyleConstants.NameAttribute);
- if (var2 instanceof HTML.Tag) {
- HTML.Tag var3 = (HTML.Tag)var2;
- return var3.isBlock();
- } else {
- return false;
- }
- }
-
- private boolean isFormElementWithContent(AttributeSet var1) {
- return this.matchNameAttribute(var1, Tag.TEXTAREA) || this.matchNameAttribute(var1, Tag.SELECT);
- }
-
- protected boolean matchNameAttribute(AttributeSet var1, HTML.Tag var2) {
- Object var3 = var1.getAttribute(StyleConstants.NameAttribute);
- if (var3 instanceof HTML.Tag) {
- HTML.Tag var4 = (HTML.Tag)var3;
- if (var4 == var2) {
- return true;
- }
- }
-
- return false;
- }
-
- private boolean noMatchForTagInAttributes(AttributeSet var1, HTML.Tag var2, Object var3) {
- if (var1 != null && var1.isDefined(var2)) {
- Object var4 = var1.getAttribute(var2);
- boolean var10000;
- if (var3 == null) {
- if (var4 == null) {
- return false;
- }
-
- var10000 = false;
- } else {
- if (var4 != null && var3.equals(var4)) {
- return false;
- }
-
- var10000 = false;
- }
-
- if (var10000) {
- return false;
- }
- }
-
- return true;
- }
-
- protected void selectContent(AttributeSet var1) throws IOException {
- Object var2 = var1.getAttribute(StyleConstants.ModelAttribute);
- this.incrIndent();
- if (var2 instanceof OptionListModel) {
- OptionListModel var3 = (OptionListModel)var2;
- int var4 = ((DefaultListModel)var3).getSize();
-
- for(int var5 = 0; var5 < var4; ++var5) {
- Option var6 = (Option)((DefaultListModel)var3).getElementAt(var5);
- this.writeOption(var6);
- }
- } else if (var2 instanceof OptionComboBoxModel) {
- OptionComboBoxModel var7 = (OptionComboBoxModel)var2;
- int var8 = ((DefaultComboBoxModel)var7).getSize();
-
- for(int var9 = 0; var9 < var8; ++var9) {
- Option var10 = (Option)((DefaultComboBoxModel)var7).getElementAt(var9);
- this.writeOption(var10);
- }
- }
-
- this.decrIndent();
- }
-
- protected void setIndentSpace(int var1) {
- this.indentSpace = var1;
- }
-
- protected void setLineLength(int var1) {
- this.maxLineLength = var1;
- }
-
- protected void startTag(Element var1) throws IOException, BadLocationException {
- if (!this.synthesizedElement(var1)) {
- AttributeSet var2 = var1.getAttributes();
- Object var3 = var2.getAttribute(StyleConstants.NameAttribute);
- HTML.Tag var4;
- if (var3 instanceof HTML.Tag) {
- var4 = (HTML.Tag)var3;
- } else {
- var4 = null;
- }
-
- if (var4 == Tag.PRE) {
- this.inPre = true;
- this.preEndOffset = var1.getEndOffset();
- }
-
- this.closeOutUnwantedEmbeddedTags(var2);
- if (this.inContent) {
- this.writeNewline();
- this.inContent = false;
- this.newlineOutputed = false;
- }
-
- if (this.completeDoc && var4 == Tag.BODY && !this.wroteHead) {
- this.wroteHead = true;
- this.indent();
- this.write("<head>");
- this.writeNewline();
- this.incrIndent();
- this.writeStyles(((HTMLDocument)((AbstractWriter)this).getDocument()).getStyleSheet());
- this.decrIndent();
- this.writeNewline();
- this.indent();
- this.write("</head>");
- this.writeNewline();
- }
-
- this.indent();
- this.write('<');
- this.write(var1.getName());
- this.writeAttributes(var2);
- this.write('>');
- if (var4 != Tag.PRE) {
- this.writeNewline();
- }
-
- if (var4 == Tag.TEXTAREA) {
- this.textAreaContent(var1.getAttributes());
- } else if (var4 == Tag.SELECT) {
- this.selectContent(var1.getAttributes());
- } else if (this.completeDoc && var4 == Tag.BODY) {
- this.writeMaps(((HTMLDocument)((AbstractWriter)this).getDocument()).getMaps());
- } else if (var4 == Tag.HEAD) {
- this.wroteHead = true;
- }
-
- }
- }
-
- protected boolean synthesizedElement(Element var1) {
- return this.matchNameAttribute(var1.getAttributes(), Tag.IMPLIED);
- }
-
- protected void text(Element var1) throws BadLocationException, IOException {
- int var2 = Math.max(this.startOffset, var1.getStartOffset());
- int var3 = Math.min(this.endOffset, var1.getEndOffset());
- if (var2 < var3) {
- if (this.segment == null) {
- this.segment = new Segment();
- }
-
- ((AbstractWriter)this).getDocument().getText(var2, var3 - var2, this.segment);
- this.newlineOutputed = false;
- if (this.segment.count > 0) {
- if (this.segment.array[this.segment.offset + this.segment.count - 1] == '\n') {
- this.newlineOutputed = true;
- }
-
- if (this.inPre && var3 == this.preEndOffset) {
- if (this.segment.count <= 1) {
- return;
- }
-
- --this.segment.count;
- }
-
- this.write(this.segment.array, this.segment.offset, this.segment.count, this.inPre ^ true, true);
- }
- }
-
- }
-
- protected void textAreaContent(AttributeSet var1) throws BadLocationException, IOException {
- Document var2 = (Document)var1.getAttribute(StyleConstants.ModelAttribute);
- if (var2 != null && var2.getLength() > 0) {
- if (this.segment == null) {
- this.segment = new Segment();
- }
-
- var2.getText(0, var2.getLength(), this.segment);
- if (this.segment.count > 0) {
- this.inTextArea = true;
- this.incrIndent();
- this.indent();
- this.write(this.segment.array, this.segment.offset, this.segment.count, true, true);
- this.writeNewline();
- this.inTextArea = false;
- this.decrIndent();
- }
- }
-
- }
-
- public void write() throws IOException, BadLocationException {
- ElementIterator var1 = ((AbstractWriter)this).getElementIterator();
- Element var2 = null;
- Object var3 = null;
- this.wroteHead = false;
- this.tempChars = null;
- this.currLength = 0;
- this.isLineEmpty = true;
- if (this.segment == null) {
- this.segment = new Segment();
- }
-
- this.inPre = false;
-
- while((var6 = var1.next()) != null) {
- if (((AbstractWriter)this).inRange(var6)) {
- if (var2 != null) {
- if (this.indentNeedsIncrementing(var2, var6)) {
- this.incrIndent();
- } else if (var2.getParentElement() != var6.getParentElement()) {
- for(Element var7 = (Element)this.blockElementStack.peek(); var7 != var6.getParentElement(); var7 = (Element)this.blockElementStack.peek()) {
- this.blockElementStack.pop();
- if (!this.synthesizedElement(var7)) {
- if (!this.matchNameAttribute(var7.getAttributes(), Tag.PRE)) {
- this.decrIndent();
- }
-
- this.endTag(var7);
- }
- }
- } else if (var2.getParentElement() == var6.getParentElement()) {
- Element var4 = (Element)this.blockElementStack.peek();
- if (var4 == var2) {
- this.blockElementStack.pop();
- this.endTag(var4);
- }
- }
- }
-
- if (var6.isLeaf() && !this.isFormElementWithContent(var6.getAttributes())) {
- this.emptyTag(var6);
- } else {
- this.blockElementStack.push(var6);
- this.startTag(var6);
- }
-
- var2 = var6;
- }
- }
-
- this.closeOutUnwantedEmbeddedTags((AttributeSet)null);
-
- while(!this.blockElementStack.empty()) {
- var2 = (Element)this.blockElementStack.pop();
- if (!this.synthesizedElement(var2)) {
- if (!this.matchNameAttribute(var2.getAttributes(), Tag.PRE)) {
- this.decrIndent();
- }
-
- this.endTag(var2);
- }
- }
-
- if (this.completeDoc) {
- this.writeAdditionalComments();
- }
-
- this.segment.array = null;
- }
-
- protected void write(char var1) throws IOException {
- this.write(var1, false);
- }
-
- private void write(char var1, boolean var2) throws IOException {
- if (var1 == '\n') {
- this.currLength = 0;
- this.out.write(this.newline);
- this.isLineEmpty = true;
- } else {
- this.isLineEmpty = false;
- this.out.write(var1);
- ++this.currLength;
- if (var2 && this.currLength >= this.maxLineLength) {
- this.writeNewline();
- }
- }
-
- }
-
- protected void write(String var1) throws IOException {
- this.write(var1, false);
- }
-
- private void write(String var1, boolean var2) throws IOException {
- int var3 = var1.length();
- if (this.tempChars == null || this.tempChars.length < var3) {
- this.tempChars = new char[var3];
- }
-
- var1.getChars(0, var3, this.tempChars, 0);
- this.write(this.tempChars, 0, var3, var2, var2);
- }
-
- private void write(char[] var1, int var2, int var3) throws IOException {
- int var4 = var2;
- this.isLineEmpty = false;
- var3 += var2;
-
- for(int var5 = var2; var5 < var3; ++var5) {
- switch (var1[var5]) {
- case '\t':
- case '\n':
- case '\r':
- break;
- case '"':
- if (var5 > var4) {
- this.out.write(var1, var4, var5 - var4);
- }
-
- var4 = var5 + 1;
- this.out.write(""");
- break;
- case '&':
- if (var5 > var4) {
- this.out.write(var1, var4, var5 - var4);
- }
-
- var4 = var5 + 1;
- this.out.write("&");
- break;
- case '<':
- if (var5 > var4) {
- this.out.write(var1, var4, var5 - var4);
- }
-
- var4 = var5 + 1;
- this.out.write("<");
- break;
- case '>':
- if (var5 > var4) {
- this.out.write(var1, var4, var5 - var4);
- }
-
- var4 = var5 + 1;
- this.out.write(">");
- break;
- default:
- if (var1[var5] < ' ' || var1[var5] > 127) {
- if (var5 > var4) {
- this.out.write(var1, var4, var5 - var4);
- }
-
- var4 = var5 + 1;
- this.out.write("");
- this.out.write(String.valueOf(var1[var5]));
- this.out.write(59);
- }
- }
- }
-
- if (var4 < var3) {
- this.out.write(var1, var4, var3 - var4);
- }
-
- }
-
- private void write(char[] var1, int var2, int var3, boolean var4, boolean var5) throws IOException {
- if (!var4) {
- int var6 = var2;
- int var7 = var2 + var3;
-
- for(int var8 = this.indexOf(var1, '\n', var2, var7); var8 != -1; var8 = this.indexOf(var1, '\n', var6, var7)) {
- if (var8 > var6) {
- if (var5) {
- this.write(var1, var6, var8 - var6);
- } else {
- this.out.write(var1, var6, var8 - var6);
- }
- }
-
- this.writeNewline();
- var6 = var8 + 1;
- }
-
- if (var6 < var7) {
- this.currLength += var7 - var6;
- if (var5) {
- this.write(var1, var6, var7 - var6);
- } else {
- this.out.write(var1, var6, var7 - var6);
- }
- }
- } else {
- int var13 = var2;
- int var14 = var2 + var3;
- if (this.currLength >= this.maxLineLength && !this.isLineEmpty) {
- this.writeNewline();
- }
-
- while(var13 < var14) {
- int var15 = this.indexOf(var1, '\n', var13, var14);
- boolean var9 = false;
- if (var15 != -1 && this.currLength + (var15 - var13) < this.maxLineLength) {
- if (var15 > var13) {
- this.write(var1, var13, var15 - var13);
- }
-
- var13 = var15 + 1;
- var9 = true;
- } else if (var15 == -1 && this.currLength + (var14 - var13) < this.maxLineLength) {
- if (var14 > var13) {
- this.write(var1, var13, var14 - var13);
- }
-
- this.currLength += var14 - var13;
- var13 = var14;
- } else {
- int var10 = -1;
- int var11 = Math.min(var14 - var13, this.maxLineLength - this.currLength - 1);
-
- for(int var12 = 0; var12 < var11; ++var12) {
- if (Character.isWhitespace(var1[var12 + var13])) {
- var10 = var12;
- }
- }
-
- if (var10 != -1) {
- var10 += var13 + 1;
- this.write(var1, var13, var10 - var13);
- var13 = var10;
- } else if (this.isLineEmpty) {
- int var20 = Math.max(0, var11);
-
- for(int var19 = var14 - var13; var20 < var19; ++var20) {
- if (Character.isWhitespace(var1[var20 + var13])) {
- var10 = var20;
- break;
- }
- }
-
- if (var10 == -1) {
- this.write(var1, var13, var14 - var13);
- var10 = var14;
- } else {
- var10 += var13;
- if (var1[var10] == '\n') {
- this.write(var1, var13, var10++ - var13);
- } else {
- ++var10;
- this.write(var1, var13, var10 - var13);
- }
- }
-
- var13 = var10;
- }
-
- var9 = true;
- }
-
- if (var9 || var13 < var14) {
- this.writeNewline();
- if (var13 < var14) {
- this.indent();
- }
- }
- }
- }
-
- }
-
- void writeAdditionalComments() throws IOException {
- Object var1 = ((AbstractWriter)this).getDocument().getProperty("AdditionalComments");
- if (var1 instanceof Vector) {
- Vector var2 = (Vector)var1;
- int var3 = 0;
-
- for(int var4 = var2.size(); var3 < var4; ++var3) {
- this.writeComment(var2.elementAt(var3).toString());
- }
- }
-
- }
-
- protected void writeAttributes(AttributeSet var1) throws IOException {
- this.convAttr.removeAttributes(this.convAttr);
- convertToHTML32(var1, this.convAttr);
- Enumeration var2 = this.convAttr.getAttributeNames();
-
- while(var2.hasMoreElements()) {
- Object var3 = var2.nextElement();
- if (!(var3 instanceof HTML.Tag) && !(var3 instanceof StyleConstants) && var3 != Attribute.ENDTAG) {
- this.write(" " + var3 + "=\"" + this.convAttr.getAttribute(var3) + "\"");
- }
- }
-
- }
-
- void writeComment(String var1) throws IOException {
- this.write("<!--");
- if (var1 != null) {
- this.write(var1);
- }
-
- this.write("-->");
- this.writeNewline();
- }
-
- protected void writeEmbeddedTags(AttributeSet var1) throws IOException {
- var1 = this.convertToHTML(var1, this.oConvAttr);
- Enumeration var2 = var1.getAttributeNames();
-
- while(var2.hasMoreElements()) {
- Object var3 = var2.nextElement();
- if (var3 instanceof HTML.Tag) {
- HTML.Tag var4 = (HTML.Tag)var3;
- if (var4 != Tag.FORM && !this.tags.contains(var4)) {
- this.write('<');
- this.write(var4.toString());
- Object var5 = var1.getAttribute(var4);
- if (var5 != null && var5 instanceof AttributeSet) {
- this.writeAttributes((AttributeSet)var5);
- }
-
- this.write('>');
- this.tags.addElement(var4);
- this.tagValues.addElement(var5);
- }
- }
- }
-
- }
-
- void writeMaps(Enumeration var1) throws IOException {
- if (var1 != null) {
- while(var1.hasMoreElements()) {
- Map var2 = (Map)var1.nextElement();
- String var3 = var2.getName();
- this.incrIndent();
- this.indent();
- this.write("<map");
- if (var3 != null) {
- this.write(" name=\"");
- this.write(var3);
- this.write("\">");
- } else {
- this.write('>');
- }
-
- this.writeNewline();
- this.incrIndent();
- AttributeSet[] var4 = var2.getAreas();
- if (var4 != null) {
- int var5 = 0;
-
- for(int var6 = var4.length; var5 < var6; ++var5) {
- this.indent();
- this.write("<area");
- this.writeAttributes(var4[var5]);
- this.write("></area>");
- this.writeNewline();
- }
- }
-
- this.decrIndent();
- this.indent();
- this.write("</map>");
- this.writeNewline();
- this.decrIndent();
- }
- }
-
- }
-
- private void writeNewline() throws IOException {
- this.out.write(this.newline);
- this.isLineEmpty = true;
- this.currLength = 0;
- }
-
- protected void writeOption(Option var1) throws IOException {
- this.indent();
- this.write('<');
- this.write("option ");
- if (var1.getValue() != null) {
- this.write("value=" + var1.getValue());
- }
-
- if (var1.isSelected()) {
- this.write(" selected");
- }
-
- this.write('>');
- if (var1.getLabel() != null) {
- this.write(var1.getLabel());
- }
-
- this.writeNewline();
- }
-
- boolean writeStyle(String var1, Style var2, boolean var3) throws IOException {
- boolean var4 = false;
- Enumeration var5 = var2.getAttributeNames();
- if (var5 != null) {
- while(var5.hasMoreElements()) {
- Object var6 = var5.nextElement();
- if (var6 instanceof CSS.Attribute) {
- String var7 = var2.getAttribute(var6).toString();
- if (var7 != null) {
- if (!var3) {
- this.writeStyleStartTag();
- var3 = true;
- }
-
- if (!var4) {
- var4 = true;
- this.indent();
- this.write(var1);
- this.write(" {");
- } else {
- this.write(";");
- }
-
- this.write(' ');
- this.write(var6.toString());
- this.write(": ");
- this.write(var7);
- }
- }
- }
- }
-
- if (var4) {
- this.write(" }");
- this.writeNewline();
- }
-
- return var4;
- }
-
- void writeStyleEndTag() throws IOException {
- this.decrIndent();
- this.indent();
- this.write("-->");
- this.writeNewline();
- this.decrIndent();
- this.indent();
- this.write("</style>");
- this.writeNewline();
- this.indent();
- }
-
- void writeStyleStartTag() throws IOException {
- this.indent();
- this.write("<style type=\"text/css\">");
- this.incrIndent();
- this.writeNewline();
- this.indent();
- this.write("<!--");
- this.incrIndent();
- this.writeNewline();
- }
-
- void writeStyles(StyleSheet var1) throws IOException {
- if (var1 != null) {
- Enumeration var2 = ((StyleContext)var1).getStyleNames();
- if (var2 != null) {
- boolean var3 = false;
-
- while(var2.hasMoreElements()) {
- String var4 = (String)var2.nextElement();
- if (!"default".equals(var4) && this.writeStyle(var4, ((StyleContext)var1).getStyle(var4), var3)) {
- var3 = true;
- }
- }
-
- if (var3) {
- this.writeStyleEndTag();
- }
- }
- }
-
- }
- }
-